
clear 
set more off
cd "$Mydirectory1/1_DataSources/CPI/"

****************
******* CPI
****************

	use CPI_1947_2017.dta, clear
	
/* Deflate income to real terms using CPI. Use CPI for all urban consumers 
   for all items for 1947-2011 - https://fred.stlouisfed.org/series/CPIAUCSL */

	gen date = date(year, "YMD")
	format date %td
	gen year2 = year(date)

* Get annual CPI
	bysort year2: egen yearCPI = mean(CPI)
	
* This CPI has 1982-1984=100
	collapse (mean) yearCPI, by(year2)
	rename year2 year_CPI
	rename yearCPI CPI
	
* Go with 1950 dollars so that father's and adult childrens' incomes are in same dollar amount
	gen test = CPI if year_CPI==1950
	egen CPI50 = min(test)
	drop test
	
	gen deflator = CPI50 /CPI 
	label var deflator "Deflator for adjusting to 1950$"
	drop CPI50

* Save
	save CPI_deflator.dta, replace
